<template>
  <nav>
    <div class="menu_box" @click.stop="emit('toOpenMenu', 'menu')">
      <div class="icons">
        <div class="icon_item"></div>
        <div class="icon_item"></div>
        <div class="icon_item"></div>
      </div>
      <div class="menu_text">{{ $t('message.menu') }}</div>
    </div>
    <span class="icon iconfont icon-twitter-fill search_icon"></span>
    <div class="nav_title">
      <Transition name="single" :duration="1">
        <span class="single_title" v-if="!showFull">w</span>
      </Transition>
      <Transition name="full">
        <span class="full_title" v-if="showFull">awwwards</span>
      </Transition>
      <span class="dot">.</span>
    </div>
    <div class="to_login">
      {{ $t('message.logUp') }}/{{ $t('message.logIn') }}
    </div>
    <div class="sub_web_btn" @click="$router.push('/animation')">
      {{ $t('message.anl') }}
    </div>
  </nav>
  <!-- banner图 -->
  <div class="banner">
    <div class="banner_head">
      <div class="left">{{ $t('message.cur.main') }} {{ curDate }}</div>
      <div class="icon iconfont icon-fenxiang right"></div>
    </div>
    <div class="user_name">Bequant</div>
    <div class="command_des">
      {{ $t('message.command.1') }}
      <div class="mark">OIMACHI</div>
      {{ $t('message.command.2') }}
      <div class="mark">OIMACHI</div>
      {{ $t('message.command.3') }}
      <div class="mark">7.42</div>
    </div>
    <div class="commands">
      <div class="command_item" v-for="item in commands" :key="item.id">
        <Circle v-bind="item" />
      </div>
    </div>
    <div class="banner_footer">
      <div class="left">
        <div class="link btn">{{ $t('message.access') }}</div>
        <div class="coll btn">{{ $t('message.coll') }}</div>
      </div>
      <div class="right">
        <div class="avatar_list">
          <div class="avatar_item" v-for="(o, i) in expertRatings" :key="o.id">
            <img
              @mouseenter="mouseHover($event, i)"
              @mouseleave="mouseleaveEv"
              :src="o.imgUrl"
              alt=""
            />
            <TooltipComp
              v-bind="{
                display: displayIdx === i,
                idx: i,
                tooltipData: o,
                disTop: disTop,
                hasSlot: false,
              }"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, shallowReactive } from 'vue';
import Circle from '@/components/circle.vue';
import type { CircleProps } from '@/components/circle.vue';
import { getCommands, getExpertRatings } from './api';
import { convertDayjs } from '@/utils/commonApi';
import TooltipComp from '@/components/tooltip.vue';

export interface Tooltip {
  score: number;
  name: string;
  from: string;
  [k: string]: any;
}
interface Commands extends CircleProps {
  [k: string]: any;
}
const emit = defineEmits(['toOpenMenu']);

const showFull = ref(true);
const curDate = convertDayjs();
const disTop = ref(0);
const displayIdx = ref(-1);
let setTimeStore: number | undefined;

const commands: Commands[] = shallowReactive([]);
getCommands().then((res) => {
  commands.push(...res);
});
const expertRatings: Tooltip[] = shallowReactive([]);
getExpertRatings().then((res) => {
  expertRatings.push(...res);
});

const mouseHover = (e: MouseEvent, i: number) => {
  setTimeStore && clearTimeout(setTimeStore);
  setTimeStore = setTimeout(() => {
    displayIdx.value = i;
    disTop.value = e.clientY;
  }, 200);
};

const mouseleaveEv = () => {
  setTimeStore && clearTimeout(setTimeStore);
  displayIdx.value = -1;
};

onMounted(() => {
  let scrollTop = 0,
    curTop = 0;
  window.onscroll = () => {
    curTop = document.documentElement.scrollTop || document.body.scrollTop;
    if (curTop > scrollTop && curTop > 84) {
      showFull.value = false;
    } else {
      showFull.value = true;
    }
    scrollTop = curTop;
  };
});
</script>

<style lang="scss" scoped>
nav {
  height: 84px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  background-color: $body-bg;
  z-index: 1;
}

.menu_box {
  padding: 0 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  height: 84px;
  border-right: 1px solid $main-border-color;

  &:hover {
    .icon_item {
      &::after {
        left: 0;
      }

      &:nth-of-type(2) {
        &::after {
          transition-delay: 0.1s;
        }
      }

      &:nth-of-type(3) {
        &::after {
          transition-delay: 0.2s;
        }
      }
    }
  }
}

.icons {
  position: relative;
  display: inline-block;
  width: 15px;
  height: 13px;

  .icon_item {
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: #202121;
    border-radius: 2px;
    overflow: hidden;

    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 100%;
      width: 100%;
      height: 100%;
      background-color: #a6abab;
      z-index: 1;
      transition: all 0.3s;
    }

    &:nth-of-type(2) {
      top: 4px;

      &::after {
        transition-delay: 0.1s;
      }
    }

    &:nth-of-type(3) {
      top: 8px;

      &::after {
        transition-delay: 0.2s;
      }
    }
  }
}

.menu_text {
  padding-left: 10px;
}

.search_icon {
  // width: 24px;
  // height: 24px;
  font-size: 22px;
  margin: 0 20px;
  cursor: pointer;
}

.nav_title {
  flex: 1;
  display: flex;
  text-align: center;
  font-size: 32px;
  justify-content: center;

  span {
    font-weight: bold;
  }

  .full_title {
    width: 170px;
  }

  .full-enter-active,
  .full-leave-active {
    transition: all 0.2s ease-out;
  }

  .full-enter-active,
  .full-leave-active {
    transition: all 0.2s ease-out;
  }

  .full-enter-from,
  .full-leave-to {
    opacity: 0;
    width: 0;
  }
}

.to_login {
  margin: 0 20px;
  font-weight: bold;
  cursor: pointer;
}

.sub_web_btn {
  width: 190px;
  line-height: 84px;
  text-align: center;
  background-color: #202121;
  color: #fff;
  cursor: pointer;
  @include hoverReduceOp();
}

.banner {
  height: 560px;
  background-image: url('https://assets.awwwards.com/awards/images/2022/04/mediamonks-SOTM-thumb.jpg');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  cursor: pointer;
  padding: 60px 80px;
  color: #fff;

  .banner_head {
    font-size: 20px;
    display: flex;
    justify-content: space-between;

    .right {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 1px solid #fff;
      font-size: 20px;
      text-align: center;
      line-height: 40px;

      &:hover {
        border-color: $second-color;
        color: $second-color;
      }
    }
  }

  .banner_footer {
    display: flex;
    justify-content: space-between;
    margin-top: 90px;

    .left {
      display: flex;

      .btn {
        height: 40px;
        border-radius: 40px;
        padding: 0 20px;
        line-height: 40px;
        color: #fff;
        font-weight: bold;
        font-size: 16px;
      }

      .link {
        background-color: $second-color;

        &:hover {
          opacity: 0.9;
        }
      }

      .coll {
        border: 1px solid #fff;
        margin-left: 20px;

        &:hover {
          border-color: $second-color;
          color: $second-color;
        }
      }
    }
  }

  .avatar_list {
    display: flex;
    .avatar_item {
      position: relative;
      margin-right: 6px;
      img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        &:hover {
          opacity: 0.55;
          & + .tooltip {
            // display: block;
          }
        }
      }
    }
  }
  .user_name {
    text-align: center;
    font-weight: bold;
    font-size: 44px;
    padding-top: 10px;
    line-height: 2;
  }

  .command_des {
    font-size: 18px;
    display: flex;
    justify-content: center;

    .mark {
      color: $second-color;
      font-weight: 500;
      padding: 0 2px;
    }
  }

  .commands {
    display: flex;
    justify-content: center;
    margin: 20px 0;
  }

  .command_item {
    margin: 0 10px;
  }
}
</style>
